﻿
    using Game.Entity.Enum;
    using Game.Entity.Platform;
    using Game.Kernel;
    using Game.Utils;
    using Game.Web.UI;
    using System;
    using System.Text;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;

namespace Game.Web.Module.WebManager
{
    partial class PublicConfigInfo : AdminPage
    {

        private void BindData()
        {
            PagerSet set = base.aidePlatformFacade.GetPublicConfigList(1, 0x2710, this.SearchItems, this.Orderby);
            if (set.PageSet.Tables[0].Rows.Count > 0)
            {
                this.rptDataList.DataSource = set.PageSet;
                this.rptDataList.DataBind();
            }
            PublicConfig publicConfigInfo = base.aidePlatformFacade.GetPublicConfigInfo((base.IntParam <= 0) ? 1 : base.IntParam);
            if (publicConfigInfo != null)
            {
                if (publicConfigInfo.ConfigKey.Equals("Lottery"))
                {
                    this.ltLotteryConfig.Text = "<a href=\"LotteryConfigInfo.aspx\" style=\"text-decoration:underline; color:Blue;\">中奖率设置</a>";
                }
                this.txtConfigID.Enabled = false;
                CtrlHelper.SetText(this.txtConfigID, publicConfigInfo.ConfigID.ToString());
                CtrlHelper.SetText(this.txtConfigKey, publicConfigInfo.ConfigKey);
                CtrlHelper.SetText(this.txtConfigName, publicConfigInfo.ConfigName);
                CtrlHelper.SetText(this.txtConfigString, publicConfigInfo.ConfigString);
                CtrlHelper.SetText(this.txtField1, publicConfigInfo.Field1);
                CtrlHelper.SetText(this.txtField2, publicConfigInfo.Field2);
                CtrlHelper.SetText(this.txtField3, publicConfigInfo.Field3);
                CtrlHelper.SetText(this.txtField4, publicConfigInfo.Field4);
                CtrlHelper.SetText(this.txtField5, publicConfigInfo.Field5);
                CtrlHelper.SetText(this.txtField6, publicConfigInfo.Field6);
                CtrlHelper.SetText(this.txtField7, publicConfigInfo.Field7);
                CtrlHelper.SetText(this.txtField8, publicConfigInfo.Field8);
            }
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            base.AuthUserOperationPermission(Permission.Edit);
            this.ProcessData();
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.Page.IsPostBack)
            {
                this.BindData();
            }
        }

        private void ProcessData()
        {
            string text = CtrlHelper.GetText(this.txtConfigKey);
            PublicConfig publicConfigInfo = base.aidePlatformFacade.GetPublicConfigInfo((base.IntParam <= 0) ? 1 : base.IntParam);
            if (!string.IsNullOrEmpty(text) && (publicConfigInfo.ConfigKey != text))
            {
                publicConfigInfo = base.aidePlatformFacade.GetPublicConfigInfo(text);
                if ((publicConfigInfo != null) && (publicConfigInfo.ConfigKey.Length > 0))
                {
                    base.ShowInfo("关键字已存在，请重新设定关键字！");
                    return;
                }
            }
            publicConfigInfo = new PublicConfig {
                ConfigKey = CtrlHelper.GetText(this.txtConfigKey),
                ConfigName = CtrlHelper.GetText(this.txtConfigName),
                ConfigString = CtrlHelper.GetText(this.txtConfigString),
                Field1 = CtrlHelper.GetText(this.txtField1),
                Field2 = CtrlHelper.GetText(this.txtField2),
                Field3 = CtrlHelper.GetText(this.txtField3),
                Field4 = CtrlHelper.GetText(this.txtField4),
                Field5 = CtrlHelper.GetText(this.txtField5),
                Field6 = CtrlHelper.GetText(this.txtField6),
                Field7 = CtrlHelper.GetText(this.txtField7),
                Field8 = CtrlHelper.GetText(this.txtField8)
            };
            Message message = new Message();
            publicConfigInfo.ConfigID = (base.IntParam <= 0) ? 1 : base.IntParam;
            message = base.aidePlatformFacade.UpdatePublicConfig(publicConfigInfo);
            if (message.Success)
            {
                base.ShowInfo("修改成功", "PublicConfigInfo.aspx?param=" + base.IntParam.ToString(), 0x4b0);
            }
            else
            {
                base.ShowError(message.Content);
            }
        }

        public string Orderby
        {
            get
            {
                if (this.ViewState["Orderby"] == null)
                {
                    this.ViewState["Orderby"] = "ORDER BY ConfigID ASC";
                }
                return (string) this.ViewState["Orderby"];
            }
            set
            {
                this.ViewState["Orderby"] = value;
            }
        }

        public string SearchItems
        {
            get
            {
                if (this.ViewState["SearchItems"] == null)
                {
                    StringBuilder builder = new StringBuilder();
                    builder.Append(" WHERE 1=1 ");
                    this.ViewState["SearchItems"] = builder.ToString();
                }
                return (string) this.ViewState["SearchItems"];
            }
            set
            {
                this.ViewState["SearchItems"] = value;
            }
        }
    }
}

